/**
 * Created by huangxuehua on 2017/11/28.
 */
//$("header>a.goBack").click(function(){
//    var flag = nUtils.getUrlParam("flag");
//    if(flag){
//        window.location.href = "./indent/indent.html?flag="+flag;
//    }else{
//        window.history.go(-1);
//    }
//
//});
var toastLoading = new auiToast({});
var xpHome = new Vue({
    el:'#app',
    data:{
        goodsOrderInfo:{},// 订单商品信息
        wuLiuInfo:{},//物流信息
        wuLiuArr:[],//物流数组信息
    },
    methods:{
        getWuLiuInfo:function(){
            toastLoading.loading({
                title:"数据加载中",
            },function(ret){
            });
            var id = nUtils.getUrlParam("orderId");
            var data ={
                "data[order_id]":id
            }
            $.ajax({
                url:nUrls.getWuLiuInfo,
                type:"POST",
                data:data,
                success:function(data){
                    var result = eval('(' + data + ')');
                    if (result && result.code == 200) {
                        xpHome.wuLiuInfo=result.data;
                        //console.log("- xpHome.wuLiuInfo--", xpHome.wuLiuInfo.Traces);
                        if(xpHome.wuLiuInfo.Traces){
                            xpHome.wuLiuArr = xpHome.wuLiuInfo.Traces.reverse();
                        }
                        toastLoading.hide();
                    }else{
                        toastLoading.hide();
                    }
                    setTimeout(function(){
                        clipBoard();
                    },500);
                },
                error: function () {
                    console.log("获得物流信息出错");
                    toastLoading.hide();
                }
            })
        },
        goOnLine:function(){  //断网刷新
            nUtils.onLine();
        }
    }
});
$(function(){
    xpHome.getWuLiuInfo();

})

function clipBoard(){

    var btns = document.querySelectorAll('.copyBtn');
    var clipboard = new Clipboard(btns);

    clipboard.on('success', function(e) {
        var toast = new auiToast(); //初始化toast事件
        toast.custom({
            title: "复制成功",
            html: '',
            duration: 2000
        })
    });
    clipboard.on('error', function(e) {
        var toast = new auiToast(); //初始化toast事件
        toast.custom({
            title: "复制失败",
            html: '',
            duration: 2000
        })
    });
}

